﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using System.Data;
using System.Data.SqlClient;
using Entities;
using System.Web;


namespace DataAccess
{
   public  class CardDA
    {
       ConnectDB cn = new ConnectDB();
       CardEntites CarE = new CardEntites();
      // THANH
       public bool GetAccountNo(CardEntites carE)
       {
           try {
                SqlConnection con = new SqlConnection(cn.ConnectionString());
               con.Open();
               SqlCommand cmd = new SqlCommand("PR_SelectCardNo_1", con);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@CardNo", carE.CardNo));
               SqlDataReader dt = cmd.ExecuteReader();
           if (dt.Read())
           {
               HttpContext.Current.Session["Block"] = dt[1].ToString();
               
               cmd.Dispose();
               return true;
           }
           else
           {
               return false;
           }
           }catch(Exception ex)
           {
               throw ex;
           }
                             
       }
       // THANH
       public bool GetPIN(CardEntites carE)
       {
           
           try{
                SqlConnection con = new SqlConnection(cn.ConnectionString());
               con.Open();
               SqlCommand cmd = new SqlCommand("ProCardSelectByPIN", con);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@CardNo", carE.CardNo));
               cmd.Parameters.Add(new SqlParameter("@PIN", carE.PIN));
               SqlDataReader dt = cmd.ExecuteReader();
           if (dt.Read())
           {
               cmd.Dispose();
               return true;
           }
           else
           {
               return false;
           }
           }catch(Exception ex)
           {
               throw ex;
           }
                                      
       }
       // THANH
       public bool BlockCard(CardEntites carE)
       {
           bool kt = true;
           try {
               SqlConnection con = new SqlConnection(cn.ConnectionString());
               con.Open();
               SqlCommand cmd = new SqlCommand("ProCardUpdateByCarNo", con);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@CardNo", carE.CardNo));
               cmd.ExecuteNonQuery();
               cmd.Dispose();
               kt=true;
           
           }
           catch(Exception ex)
           {
               throw ex;
           }
           
           return kt;
       }

       public DataTable GetCardNo(CardEntites card)
       {
           DataTable dt = Data.ExeStoredWithParamToDataTable("ProAccountSelectByCardNo", "@CardNo", card.CardNo);
           return dt;
       }
    }
}
